﻿using DataBase;
using DataBase.Utils;
using GreenXi.Help.Curve;
using GreenXi.Model;
using GreenXi.Pages.Power;
using Prism.Commands;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Drawing.Drawing2D;
using ZedGraph;
using static GreenXi.Help.Curve.SmoothChart;

namespace GreenXi.ViewModel
{
    public class DecisionBoxBindingSettingsViewModel : MonitoringModel
    {
        private static string PressId = "1";

        private List<Decision> Decisionlist;
        DecisionBoxBindingDettings context;
        public DecisionBoxBindingSettingsViewModel(DecisionBoxBindingDettings _context)
        {
            context = _context;
           
            SwitchPress = new DelegateCommand<object>((p) => { SwitchPress_Click(); }); //切换压机
            Draw = new DelegateCommand<object>((p) => { Draw_Click(p); });
            UpdateColumn = new DelegateCommand<object>((p) => { UpdateColumn_Click(p); });
        }

     
        private void UpdateColumn_Click(object param)
        {
            var paramss = param as Decision;
            MyDbContext.Instance.DecisionUpdate(paramss);
            
        }
        private void SwitchPress_Click()
        {
            if (Press2)
            {
                PressId = "2";
            }
            else
            {
                PressId = "1";
            }
          
        }
        private void Draw_Click(object param)
        {
            zedGraphDraw(context.zedGraphControl, (int)param);
        }

      
        public void zedGraphDraw(ZedGraphControl zedGraphControl, int id)
        {
            ZedGraph.GraphPane myPane = zedGraphControl.GraphPane;
            //zedGraphControl.GraphPane.CurveList.Clear();//之前数据清除
            //从数据库获取数据加载判断框
            var list = MyDbContext.Instance.GetDecisionById(id);
            foreach (var item in list)
            {
                double[] x = { item.X1, item.X2, item.X2, item.X1, item.X1 };
                double[] y = { item.Y1, item.Y1, item.Y2, item.Y2, item.Y1 };

                DecusionType type = new();
                #region 判断类型后期从数据库获得
                var decisiontype = MyDbContext.Instance.GetDecisionType(item.Type);
                if (decisiontype != null)
                {
                    type.BottomType = (DashStyle)decisiontype.Bottom;
                    type.TopType = (DashStyle)decisiontype.Top;
                    type.LeftType = (DashStyle)decisiontype.Left;
                    type.RightType = (DashStyle)decisiontype.Right;
                }

                #endregion
                SmoothChart.SmoothChartDemo(myPane, x, y, type, item.ID);
            }

            zedGraphControl.AxisChange();
            zedGraphControl.Refresh();
        }

        public void zedGraphDisDraw(ZedGraphControl zedGraphControl, int id)
        {
            ZedGraph.GraphPane myPane = zedGraphControl.GraphPane;
            //从数据库获取数据加载判断框
            var list = MyDbContext.Instance.GetDecisionById(id);
            foreach (var item in list)
            {
                double[] x = { item.X1, item.X2, item.X2, item.X1, item.X1 };
                double[] y = { item.Y1, item.Y1, item.Y2, item.Y2, item.Y1 };

                DecusionType type = new();
                #region 判断类型后期从数据库获得
                var decisiontype = MyDbContext.Instance.GetDecisionType(item.Type);
                if (decisiontype != null)
                {
                    type.BottomType = (DashStyle)decisiontype.Bottom;
                    type.TopType = (DashStyle)decisiontype.Top;
                    type.LeftType = (DashStyle)decisiontype.Left;
                    type.RightType = (DashStyle)decisiontype.Right;
                }

                #endregion
                SmoothChart.SmoothChartDemo(myPane, x, y, type, item.ID);
            }

            zedGraphControl.AxisChange();
            zedGraphControl.Refresh();
        }
    }
}
